<!--
 * @Author: ChunLai
 * @Date: 2021-11-15 09:29:54
 * @LastEditTime: 2025-08-21 16:18:25
 * @Description: 新版告知详情 --- 长城
 * @FilePath: \02.bldinsure\src\views\healthy\detail.vue
-->
<template>
  <div class="healthy-wrap">
    <WarnMsgs :msg="tipMsg" v-if="tipMsg !== ''" />
    <div :class="{ disabledForm: disabledEdit }">
      <div
        class="modules"
        v-for="(item, index) in pageData"
        :key="`modue${index}`"
      >
        <div class="notice-mode-head">
          <span class="head-box">{{ `${utypeName}${item.moduleName}` }}</span> 
        </div>
        <ul class="module-ul">
          <template v-for="(unit, idx) in item.questionsList">
            <li
              class="module-li"
              :key="`unit${index}-${idx}`"
              :id="`${item.type}-${idx}`"
              v-if="!unit.isHide"
            >
              <div
                class="base-unit-subject"
                :class="{ hasBtns: unit.rightBtns }"
              >
                <div class="subject-txt ftw5" v-html="unit.impartContent"></div>
                <div class="subject-btns" v-if="unit.rightBtns">
                  <span
                    class="btn-span"
                    :class="{ 'btn-y': unit.impartYesOrNo === 'Y' }"
                    @click="setBtnValue(index, idx, 'Y', unit)"
                    >是</span
                  >
                  <span
                    class="btn-span"
                    :class="{ 'btn-y': unit.impartYesOrNo === 'N' }"
                    @click="setBtnValue(index, idx, 'N', unit)"
                    >否</span
                  >
                </div>
              </div>
              <div
                class="base-unit-answer"
                v-if="
                  (unit.rightBtns && unit.impartYesOrNo === 'Y') ||
                  !unit.rightBtns
                "
              >
                <template v-for="(ele, j) in unit.answer">
                  <div
                    class="answer-li"
                    :class="ele.label.indexOf('收入来源') != -1 ? 'label3' : ''"
                    :key="`${unit.impartCode}-${j}`"
                    v-if="!ele.isHide"
                  >
                    <div class="answer-label" v-if="ele.label !== ''">
                      {{ ele.check === "1" ? "*" : "" }}{{ ele.label }}
                    </div>
                    <!-- 单选按钮/年收入 -->
                    <div
                      class="checkboxs-box"
                      v-if="ele.inputType === 'SingleCheck'"
                    >
                      <template>
                        <span
                          v-for="income in ele.checkboxs"
                          class="checkbox-span"
                          :class="{ 'bg-col': ele.value == income.value }"
                          :key="`income-${income.value}`"
                          @click="setCheckboxs(index, idx, j, income)"
                        >
                          {{ income.label }}
                        </span>
                      </template>
                    </div>
                    <!-- 多选按钮/年收入 -->
                    <div
                      class="checkboxs-box"
                      v-else-if="ele.inputType === 'checksbox'"
                    >
                      <template>
                        <span
                          v-for="income in ele.checkboxs"
                          class="checkbox-span"
                          :class="{
                            'bg-col': ele.value.indexOf(income.value) !== -1,
                          }"
                          :key="`income-${income.value}`"
                          @click="setMultiChecs(index, idx, j, income)"
                        >
                          {{ income.label }}
                        </span>
                      </template>
                    </div>
                    <!-- 单选按钮/answer列表 -->
                    <div
                      class="checkboxs-box"
                      v-else-if="ele.inputType === 'radio'"
                    >
                      <template>
                        <span
                          v-for="obj in ele.checkboxs"
                          class="checkbox-span"
                          :class="{ 'bg-col': ele.value == obj.value }"
                          :key="`obj-${obj.value}`"
                          @click="setRadioboxs(index, idx, j, obj)"
                        >
                          {{ obj.label }}
                        </span>
                      </template>
                    </div>
                    <!-- 输入框 -->
                    <div
                      class="input-box"
                      :class="{ w100: ele.label === '' }"
                      v-else
                    >
                      <input
                        class="md-input"
                        type="number"
                        v-model="ele.value"
                        v-if="ele.inputType == 'number'"
                        @blur="validInfo(ele)"
                        :disabled="!!ele.readOnly"
                        onkeyup="value=value.replace(/[^0-9.]/g,'')"
                      />
                      <input
                        class="md-input"
                        v-else
                        :type="ele.inputType || 'text'"
                        :placeholder="`${ele.tip || '请输入'}`"
                        v-model="ele.value"
                        :disabled="!!ele.readOnly"
                        @input="(e) => formatRule(e, ele.inputType)"
                      />
                    </div>
                  </div>
                </template>
              </div>
            </li>
          </template>
        </ul>
      </div>
    </div>
    <div style="padding: 20px 0 80px">
      <van-divider>用心服务每一位</van-divider>
    </div>
    <FooterBtns btnNum="1" @saveForm="nextStep" />
  </div>
</template>

<script>
import AgentStatement from "./components/AgentStatement";
import WarnMsgs from "./components/WarnMsgs";
import { detailMixin } from "./detail_mx.js";

export default {
  name: "CommonNoticeDetail",
  components: { AgentStatement, WarnMsgs },
  data() {
    return {
      bbrIdx: 0,
    };
  },
  computed: {
    utypeName() {
      if (this.utype == "tbr") return "投保人";
      if (this.utype == "bbr") return "被保人";
      if (this.utype == "3") return "代理人";
      if (this.utype == "4") return "重庆问卷";
      if (this.utype == "5") return "万能险评估问卷";
    },
    submitType() {
      if (this.utype == "tbr") return "1";
      if (this.utype == "bbr") return "2";
    },
    isApplicant() {
      return this.utype == "tbr";
    },
  },
  mixins: [detailMixin],
  async created() {
    this.$store.commit("updateLoad", false);
    /* === 1.获取路由数据 === */
    const querys = this.$route.query;
    this.queryData = querys;
    // 1投保人告知，2被保人告知，3代理人告知，4重庆问卷，5万能险评估问卷
    if (querys.type !== void 0) {
      this.utype = querys.type;
    }
    if (querys.idx !== void 0) {
      this.bbrIdx = querys.idx * 1;
    }
    // 分享
    if (this.$getDataFromUrl("utype")) {
      this.utype = this.$getDataFromUrl("utype");
    }
    if (this.$getDataFromUrl("idx")) {
      this.bbrIdx = this.$getDataFromUrl("idx") * 1;
    }
    await this.initPageDatas();
  },
  methods: {
    async initPageDatas() {
      let res = await this.$store.dispatch("json/getNoticeJson");
      // console.log("healthy", res)
      // 过滤
      const userObj = this.isApplicant
          ? this.applicant
          : this.apiBbrMult[this.bbrIdx * 1],
        curAge = this.$GlobalFuns.userAge(userObj.birthDate),
        curSex = userObj.sex;
      // 用户类型限制告知内容
      if (res.userTypeLimit) {
        res.Datas = res.Datas.filter(
          (ele) => ele.userTypeLimit && ele.userTypeLimit === this.utype
        );
      }
      //长城非首单,不需要健康告知
      if (
        this.firstBillRelateCode.includes(this.mainRiskCode) &&
        this.isFiristBill == "1"
      ) {
        res.Datas = res.Datas.filter((ele) => ele.type != "healthy");
      }
      // 百年19138版本
      if (res.jsonName === "healthy19138") {
        if (!this.isSameToApplicant && this.isApplicant) {
          res.Datas = res.Datas.filter((ele) => ele.isAppntWithNotSelf);
        } else {
          res.Datas = res.Datas.filter((ele) => !ele.isAppntWithNotSelf);
        }
      }
      /* ===== 阳光 ===== */
      if (this.compEngName === "yangguang") {
        // 是否有豁免险
        // let hasExempt = false;
        if (!this.isSameToApplicant && this.isApplicant) {
          res.Datas = res.Datas.filter((ele) => ele.isAppntWithNotSelf);
        } else {
          res.Datas = res.Datas.filter((ele) => !ele.isAppntWithNotSelf);
        }
      }
      // 条件限制过滤配置中的健康告知数据(女性+儿童)
      res.Datas.forEach((item) => {
        item.questionsList = item.questionsList.filter((ele) => {
          // 健康告知-答案列表赋值
          if (ele.maxAge !== undefined) {
            return curAge <= ele.maxAge;
          } else if (ele.minAge !== undefined && ele.sexLimit !== undefined) {
            return curAge >= ele.minAge && curSex == ele.sexLimit;
          } else {
            return true;
          }
        });
      });
      // 特殊字段赋值处理
      res.Datas.forEach((item) => {
        item.questionsList.forEach((ele) => {
          // 健康告知-答案列表赋值
          if (
            item.type === "healthy" &&
            ele.answer.length === 0 &&
            res.answerModules &&
            ele.answerKey
          ) {
            ele.answer = res.answerModules[ele.answerKey];
          }
          if (!ele.impartCheck && ele.impartYesOrNo == "") {
            ele.impartYesOrNo = "N";
          }
          /* === 特殊处理 === */
          if (ele.impartType) {
            // 1.身高/体重
            if (ele.impartType === "heightWeight") {
              if (userObj.height) {
                ele.answer[0].value = userObj.height;
              }
              if (userObj.weight) {
                ele.answer[1].value = userObj.weight;
              }
            }
            // 2.年收入
            if (ele.impartType === "yearIncome") {
              if (userObj.income) {
                ele.answer[0].value = userObj.income;
              }
            }
            /**社保 */
            if (ele.impartType === "socialInsuFlag") {
              ele.impartYesOrNo = userObj.socialInsuFlag;
              ele.answer[0].value =
                userObj.socialInsuFlag == "Y" ? "社会医疗保险" : "";
            }
          }
        });
      });
      let tempDatas = res.Datas;
      this.pageData = JSON.parse(JSON.stringify(tempDatas));
      this.dataEcho();
    },
  },
};
</script>
<style lang="less" scoped>
.md-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding-left: 4px;
  color: #323233;
  text-align: left;
  border: 0;
}

.healthy-wrap {
  overflow: hidden;

  .modules {
    background: #ffffff;

    .module-title {
      display: flex;
      padding: 10px 12px;
      font-size: 16px;
      display: flex;
      align-items: center;

      .tagline {
        width: 4px;
        height: 14px;
        border-radius: 2px;
        margin-right: 5px;
        background: #da251d;
      }
    }

    .module-ul {
      display: flex;
      flex-direction: column;
      padding: 0 14px;
      .module-li {
        padding: 5px 0 10px;
        position: relative;
        .shadows {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background-color: rgba(222, 222, 222, 0.1);
        }

        .base-unit-subject {
          display: flex;
          align-items: flex-start;
          flex-direction: column;

          &.hasBtns {
            justify-content: space-between;
          }

          .subject-txt {
            line-height: 1.5;
          }

          .subject-btns {
            display: flex;
            align-items: center;
            margin-top: 6px;
            flex-wrap: wrap;
            width: 100%;

            .btn-span {
              display: flex;
              align-items: center;
              justify-content: center;
              flex: 1;
              height: 36px;
              color: #747474;
              background-color: #c2c2c2;
              margin: 5px;
              border-radius: 2px;
              background: #f7f7f7;
              overflow: hidden;

              &.btn-y {
                background: #fff0f0;
                color: #f54040;
                position: relative;

                &::after {
                  content: "";
                  position: absolute;
                  right: 0;
                  bottom: 0;
                  width: 24px;
                  height: 18px;
                  background-image: url("https://wxou.mschn.cn/app_h5/insurepics/icons/check.png");
                  background-size: cover;
                }
              }
            }
          }
        }

        .base-unit-answer {
          display: flex;
          flex-direction: column;

          .answer-li {
            display: flex;
            // align-items: center;
            justify-content: space-between;
            padding: 6px 0;

            .answer-label {
              color: #da251e;
              line-height: 26px;
            }
            &.label3 {
              align-items: flex-start;
              padding-top: 10px;
              .answer-label {
                line-height: 24px;
              }
            }

            .input-box {
              line-height: 2;
              border: 1px solid #dadada;

              &.w100 {
                width: 100%;
              }
            }

            .checkboxs-box {
              display: flex;
              align-items: center;
              flex-wrap: wrap;
              justify-content: flex-end;
              width: 70%;

              .checkbox-span {
                padding: 4px 10px;
                border: 1px solid #cccccc;
                color: #999;
                border-radius: 4px;
                line-height: 1;
                margin-bottom: 6px;

                &.bg-col {
                  border: 1px solid #fb8c89;
                  background-color: #fb8c89;
                  color: #fff;
                }

                &:not(:first-child) {
                  margin-left: 10px;
                }
              }
            }
          }
        }
      }
    }
  }
}

.healthy-wrap {
  /deep/ .van-popup {
    background-color: rgba(0, 0, 0, 0);
    z-index: 100 !important;
  }

  /deep/.van-overlay {
    z-index: 100 !important;
  }
}
</style>
